<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *项目管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('start','off');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择信息！','error');
	}
}
$return['status']=array('未启用','已启用','待审核');
$return['pay']=$this->xinzhis;
if($_RQ['op']=='list'){
	$params=array();
	$params['uniacid']=$_SESSION['uniacid'];
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_aihire_merch',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['url']=custom_url('jy_aihire/merch_detail//id='.$item['id'],true);
			$item['pcd']=json_decode($item['pcd'],true);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'企业列表'),
			array('op'=>'edit','title'=>'添加企业'),
		),
		'list'=>array('data'=>'list','edit'=>true,'list'=>array(
			array('name'=>'paixu','title'=>'排序','type'=>'string'),
			array('name'=>'title','title'=>'企业名称','type'=>'string'),
			array('name'=>'uname','title'=>'账号','type'=>'string'),
			array('name'=>'name','title'=>'姓名','type'=>'string'),
			array('type'=>'pcd','title'=>'城市','name'=>'pcd'),
			array('name'=>'address','title'=>'地址','type'=>'string'),
			array('name'=>'looks','title'=>'浏览数量','type'=>'string'),
			array('name'=>'url','title'=>'复制链接','type'=>'copy'),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
			array('name'=>'ishot','title'=>'是否置顶','type'=>'radio','options'=>'ishot'),
			array('name'=>'status','title'=>'是否启用','type'=>'switch','set'=>'set'),
		),'action'=>array(
			array('title'=>'置顶','type'=>'modal','op'=>'zhiding','action'=>'item_list','show'=>array('ishot'=>0)),
			array('title'=>'取消置顶','type'=>'post','op'=>'notop','action'=>'item_list','show'=>array('ishot'=>1)),
		)),
		'search'=>array(
			array('name'=>'title','title'=>'企业名称','type'=>'string','width'=>'15'),
			array('name'=>'status','title'=>'状态','type'=>'radio','width'=>'15','options'=>'status'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_aihire_merch',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['images']=json_decode($item['images'],true);
		$item['tui_ids']=json_decode($item['tui_ids'],true);
		$item['lat_lng']=json_decode($item['lat_lng'],true);
	}else{
		$item=array();
	}
	$item['pcd']=json_decode($item['pcd'],true);
	$item['upass']='';
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'企业名称','name'=>'title','help'=>''),
					array('type'=>'image','title'=>'企业LOGO','name'=>'logo','help'=>''),
					array('type'=>'text','title'=>'企业描述','name'=>'desc','help'=>''),
					array('type'=>'radio','title'=>'企业性质','name'=>'type','options'=>'merch_type'),
					array('type'=>'radio','title'=>'企业规模','name'=>'teamtype','options'=>'teamtype'),
					array('type'=>'checkbox','title'=>'所属行业','name'=>'cids','options'=>'groups'),
					array('type'=>'richtext','title'=>'企业详情','name'=>'content','help'=>''),
					array('type'=>'pcd','title'=>'城市','name'=>'pcd'),
					array('type'=>'string','title'=>'地址','name'=>'address'),
					array('type'=>'lat_lng','title'=>'坐标','name'=>'lat_lng'),
				    array('name'=>'mid','title'=>'发布人','type'=>'choose','action'=>'core/member.get_member/'),
					array('name'=>'uname','must'=>true,'title'=>'账户名','type'=>'string'),
					array('name'=>'upass','title'=>'账户密码','type'=>'string'),
					array('name'=>'name','title'=>'联系人姓名','type'=>'string'),
					array('name'=>'mobile','title'=>'联系人电话','type'=>'string'),
					array('type'=>'string','title'=>'浏览量','name'=>'looks','help'=>''),
					array('type'=>'switch','title'=>'是否启用','name'=>'status','help'=>'设置是否启用'),
					array('name'=>'paixu','title'=>'排序','type'=>'string'),
				)
			),
			array(
				'title'=>'企业资质',
				'list'=>array(
					array('type'=>'string','title'=>'开户银行','name'=>'banktitle','help'=>''),
					array('type'=>'string','title'=>'银行卡号','name'=>'banksn','help'=>''),
					array('type'=>'image','title'=>'营业执照','name'=>'codeimg','help'=>''),
					array('type'=>'string','title'=>'执照编号','name'=>'codesn','help'=>''),
					array('type'=>'string','title'=>'法人姓名','name'=>'codename','help'=>''),
					array('type'=>'image','title'=>'法人身份证正面','name'=>'codeimg1','help'=>''),
					array('type'=>'image','title'=>'法人身份证背面','name'=>'codeimg2','help'=>''),
				)
			),
			/*array(
				'title'=>'关联推送',
					'list'=>array(
						array('type'=>'choose_many','action'=>'jy_aihire/item_list/choose_items/imgtitle=1','name'=>'tui_ids','title'=>'选择要关联的信息'),
					)
			),*/
		)
	);
	$groups=pdo_getall('jy_aihire_merch_group',array('uniacid'=>$_SESSION['uniacid']));
	$return['groups']=array();
	foreach($groups as $gv){
		$return['groups'][$gv['id']]=$gv['title'];
	}
	$return['merch_type']=$this->merch_type;
	$return['teamtype']=$this->teamtype;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['pcd']['province']){
			exi('城市不能为空！','error');
	}
	if(!$postdata['images']){
			//exi('图片不能为空！','error');
	}
	if(!$postdata['name']){
			exi('联系人姓名不能为空！','error');
	}
	if(empty($postdata['lat_lng'])){
			//exi('请选择坐标！','error');
	}
	if($postdata['pcd']){
		if($postdata['pcd']['city']){
			if($postdata['pcd']['city']=='北京市' || $postdata['pcd']['city']=='上海市' || $postdata['pcd']['city']=='天津市'){
				$address=$postdata['pcd']['city'].' 市辖区';
			}else{
				$address=$postdata['pcd']['province'].' '.$postdata['pcd']['city'];
			}
			$code=pdo_getcolumn('core_area',array('address'=>$address),'parent_code');
		}
	}
	$data=array(
		'title'=>trim($postdata['title']),
		'logo'=>trim($postdata['logo']),
		'desc'=>trim($postdata['desc']),
		'mid'=>intval($postdata['mid']),
		'content'=>trim($postdata['content']),
		'uname'=>trim($postdata['uname']),
		'name'=>trim($postdata['name']),
		'mobile'=>trim($postdata['mobile']),
		'address'=>trim($postdata['address']),
		'codesn'=>trim($postdata['codesn']),
		'codeimg'=>trim($postdata['codeimg']),
		'codeimg1'=>trim($postdata['codeimg1']),
		'codeimg2'=>trim($postdata['codeimg2']),
		'codename'=>trim($postdata['codename']),
		'banktitle'=>trim($postdata['banktitle']),
		'banksn'=>trim($postdata['banksn']),
		'status'=>intval($postdata['status']),
		'pcd'=>ijson_encode($postdata['pcd']),
		'code'=>$code,
		'looks'=>intval($postdata['looks']),
		'paixu'=>intval($postdata['paixu']),
		'type'=>intval($postdata['type']),
		'teamtype'=>intval($postdata['teamtype']),
		'cids'=>trim($postdata['cids']),
	);
	if($postdata['upass']){
		$data['upass']=base64_encode($postdata['upass']);
	}
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_aihire_merch',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		pdo_insert('jy_aihire_merch',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的企业！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_aihire_merch',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_aihire_merch',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}